package com.ozy.kxreader

import android.content.Context
import android.widget.ImageView
import android.widget.Toast
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.ozy.kxreader.base.BaseApplication

/**
 * Created by 欧源 on 2018/1/30.
 */


fun getAppComponent() = BaseApplication.instance.appComponent


var toast: Toast? = null

fun toast(text: String) {
    if (toast == null) {
        toast = Toast.makeText(BaseApplication.instance, text, Toast.LENGTH_SHORT)
    }
    toast!!.setText(text)
    toast!!.show()
}



fun loadImage(context: Context, url: String, imageView: ImageView?) {
    loadImage(context, url, -1, -1, imageView)
}

fun loadImage(context: Context, url: String, placeholder: Int, error: Int, imageView: ImageView?) {

    var options = RequestOptions()
            .skipMemoryCache(true)
            .diskCacheStrategy(DiskCacheStrategy.DATA);

    if (placeholder > 0)
        options.placeholder(placeholder)

    if (error > 0)
        options.error(error)
    Glide.with(context)
            .load(url)
            .apply(options)
            .into(imageView)
}